class Solution {
public:
    string longestPalindrome(string s) {
        int ret = 0;
        pair<int,int> ss;
        vector<vector<int> > dp(s.size(),vector<int>(s.size(),0));
        for(int i = 0;i < s.size();i++){
            dp[i][i] = 1;
        }
        for(int i = s.size() - 1;i >= 0;i--){
            for(int j = i + 1;j < s.size();j++){
                if(s[i] == s[j]){
                    if(j - i <= 1 || dp[i+1][j-1] == 1){
                        dp[i][j] = 1;
                        if(j - i + 1 > ret){
                            ret = j - i + 1;
                            ss.first = i;
                            ss.second = j;
                        }
                    }
                }
            }
        }
        return string(s.begin()+ss.first,s.begin()+ss.second+1);
    }
};
